#include "uart.c"
#include "timer.c"

unsigned int count = 0;
// 中断 ISR
// interrupt service routine
void timer0_ISR() interrupt 1
{
    if (count < 10)
    {
        count++;
    }
    else
    {
        printf("timer0 interrupt!\n");
        count = 0;
    }
}

sbit BTN_RAND = P2 ^ 1;
sbit BTN_SEED = P2 ^ 2;
sbit BTN_TH_TL = P2 ^ 3;

void main()
{
    uart_init();
    timer0_init();
    while (1)
    {
        if (BTN_RAND == 0)
        {
            while (BTN_RAND == 0)
            {
            }

            printf("RAND=%u\n", timer_rand());
        }

        if (BTN_SEED == 0)
        {
            while (BTN_SEED == 0)
            {
            }

            printf("SEED=%u\n", update_timer_seed());
        }
        if (BTN_TH_TL == 0)
        {
            while (BTN_TH_TL == 0)
            {
            }
            printf("THTL=0x%04X\n", (unsigned int)(TH0 << 8) | TL0);
        }
    }
}
